package com.purchase.ml.mapper.prod;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.purchase.ml.bean.req.dealer.DealerCategoryEditDto;
import com.purchase.ml.bean.req.prod.SysCategoryQueryDto;
import com.purchase.ml.entity.dealer.SysDealer;
import com.purchase.ml.entity.prod.SysCategory;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author :zxm
 * @date :2021/2/25 18:57
 * @description :some description
 **/

@Mapper
@Repository
public interface SysCategoryMapper extends BaseMapper<SysCategory> {
    /**
     * 查询主经销商所有的目录：实际为查询主经销商
     * @param dealerId
     * @return
     */
    List<Long> selectDealerCategoryIds(@Param("state") Integer state,@Param("dealerId") Long dealerId);

    /**
     * 查询对应商户对应状态的所有目录IDS
     * @param dealerId
     * @return
     */
    List<Long> selectDealerCategoryIdsByState(@Param("state") Integer state,@Param("dealerId") Long dealerId);
    /**
     * 修改经销商-目录中间表
     * @param dealerCategoryEditDto
     * @return
     */
    int updateDealerCategory(@Param("dto") DealerCategoryEditDto dealerCategoryEditDto,@Param("dealerId")Long dealerId);

    /**
     * 通过商品分类id查询出该商品分类
     * @param categoryId
     * @return
     */
    @Select("select * from sys_category where category_id=#{categoryId}")
    SysCategory findCategoryByCategoryId(@Param("categoryId") Long categoryId);

    @Update("update sys_category set state=#{state} where id=#{id}")
    int updateCategory(@Param("id") Long id,@Param("state")Integer state);

    /**
     * 查询对应状态下的产品分类
     * @param normalState
     * @param dealerId
     * @return
     */
    @Select("select category_id as categoryId from sys_dealer_category where dealer_id=#{dealerId} and `state`=#{state}")
    List<Long> selectDealerCategoryIdsState(@Param("state") Integer normalState,@Param("dealerId") Long dealerId);

    List<SysCategory> selectDealerCategoryPages(@Param("dto") SysCategoryQueryDto dto);
}
